//获取应用实例
const app = getApp();

//声明全局变量
let proListToTop = [], menuToTop = [], MENU = 0, windowHeight, timeoutId;
Page({

  data: {
    staticImg: app.globalData.staticImg,
    currentActiveIndex: 0,
    // 接口返回的商品数组
    navList: [],
    animate:'',
    goodsList:[],
    shopList:[],
    page:1
  },
  onLoad: function (e) {
    console.log(e.name)
    this.setData({
      searchName:e.name
    })
    wx.setNavigationBarTitle({
      title: e.name,
    })
    this.getList();
  },

  //获取商品列表
  getList() {
    wx.showLoading({
      title: '加载中',
      mask: false
    })
    var that = this;
    wx.request({
      url: app.globalData.api + '/app.php?c=Pdd&a=getGoodsList',
      data:
      {
        token:app.globalData.token,
        keyword:that.data.searchName,
        page:that.data.page,
        page_size:10
      },
      headers: {
        'platform': '' + app.globalData.platform,
        'version': '' + app.globalData.version,
      },
      method: 'POST',
      dataType: 'json',
      success: function (res) {
        console.log(res);
        wx.hideLoading();
        if(res.data.code==0){
          that.setData({
            shopList: that.data.shopList.concat(res.data.data.list)
          })
        }else{
          wx.showToast({
            title: ''+res.data.msg,
            icon:'none'
          })
        }
      }, fail: function () {
        wx.hideLoading();
      }
    });
  },

  goodDetail: function (e) {
    console.log(app.globalData.token)
    if (app.globalData.token != '') {
      console.log(e);
      wx.navigateTo({
        url: '/pages/shop/rx-item?id=' + e.currentTarget.dataset.id,
      })
    } else {
      wx.reLaunch({
        url: '/pages/mine/login',
      })
    }
  },
  // 获取系统的高度信息
  getSystemInfo() {
    let self = this
    wx.getSystemInfo({
      success: function (res) {
        windowHeight = res.windowHeight / 2
      }
    })
  },
  /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading(); //在标题栏中显示加载图标
    setTimeout(function () {
      wx.stopPullDownRefresh(); //停止加载
      wx.hideNavigationBarLoading(); //隐藏加载icon
    }, 2000)
    this.setData({
      page: 1,
      shopList: []
    })
    that.getList();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    // that.setData({
    //   page: that.data.page + 1
    // })
    // that.getList();
  },

})